{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "9d8dd977",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"../src/file.txt\", \"wt\", encoding=\"utf-8\") as out_file:\n",
    "    out_file.write(\"该文本会写入到文件中\\n看到我了吧！\")\n",
    "# 默认写入的是国标，\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "00b490d5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "该文本会写入到文件中\n",
      "看到我了吧！\n"
     ]
    }
   ],
   "source": [
    "with open('../src/file.txt', 'r', encoding='utf-8') as f:\n",
    "    print(f.read())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3ac17f93",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "该文本会写入到文件中\n",
      "\n",
      "看到我了吧！\n"
     ]
    },
    {
     "ename": "",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31mThe Kernel crashed while executing code in the current cell or a previous cell. \n",
      "\u001b[1;31mPlease review the code in the cell(s) to identify a possible cause of the failure. \n",
      "\u001b[1;31mClick <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a> for more info. \n",
      "\u001b[1;31mView Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details."
     ]
    }
   ],
   "source": [
    "%timeit\n",
    "with open('../src/file.txt', 'r', encoding='utf-8') as f:\n",
    "    for line in f:\n",
    "        print(line)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d40c0893",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
